cmake_minimum_required(VERSION 3.20)
project(ffmpeg_demo)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置FFmpeg路径
set(FFMPEG_PATH "${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg-build")
set(FFMPEG_INCLUDE_DIRS "${FFMPEG_PATH}/include")
set(FFMPEG_LIB_DIRS "${FFMPEG_PATH}/lib")

# 包含目录
include_directories(${FFMPEG_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

# 链接目录
link_directories(${FFMPEG_LIB_DIRS})

# 查找FFmpeg库
find_library(AVCODEC_LIBRARY avcodec PATHS ${FFMPEG_LIB_DIRS} REQUIRED)
find_library(AVFORMAT_LIBRARY avformat PATHS ${FFMPEG_LIB_DIRS} REQUIRED)
find_library(AVUTIL_LIBRARY avutil PATHS ${FFMPEG_LIB_DIRS} REQUIRED)
find_library(AVFILTER_LIBRARY avfilter PATHS ${FFMPEG_LIB_DIRS} REQUIRED)
find_library(SWSCALE_LIBRARY swscale PATHS ${FFMPEG_LIB_DIRS} REQUIRED)
find_library(SWRESAMPLE_LIBRARY swresample PATHS ${FFMPEG_LIB_DIRS} REQUIRED)

# 设置FFmpeg库列表
set(FFMPEG_LIBRARIES
    ${AVCODEC_LIBRARY}
    ${AVFORMAT_LIBRARY}
    ${AVUTIL_LIBRARY}
    ${AVFILTER_LIBRARY}
    ${SWSCALE_LIBRARY}
    ${SWRESAMPLE_LIBRARY}
)

# 查找SDL2库
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)

# 可执行文件
add_executable(video_info src/video_info.cpp)
add_executable(frame_decoder src/frame_decoder.cpp)
add_executable(video_player src/video_player.cpp)

# 链接库
target_link_libraries(video_info ${FFMPEG_LIBRARIES})
target_link_libraries(frame_decoder ${FFMPEG_LIBRARIES})
target_link_libraries(video_player ${FFMPEG_LIBRARIES} ${SDL2_LIBRARIES})

# 设置输出目录
set_target_properties(video_info frame_decoder video_player
    PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin
)
